<template>
  <div class="sports-events">
    <section class="common-bar search-bar clear">
      <template>
        <el-radio-group class="fl" v-model="select_type" @change="getList">
          <el-radio
            v-for="(item,index) of selectOption"
            :key="index"
            :label="item.value"
          >{{item.label}}</el-radio>
        </el-radio-group>
      </template>
    </section>
    <section class="common-cards activities-container">
      <div class="search-bar clear">
        <template>
          <el-radio-group class="fl" v-model="order" @change="getList">
            <el-radio v-for="(item,index) of orderOption" :key="index" :label="item.value">
              {{item.label}}
              <i class="el-icon-sort-down"></i>
            </el-radio>
          </el-radio-group>
        </template>
        <div class="select-tools fr">
          <template>
            <el-select v-model="level_type" placeholder="请选择赛事" @change="getList">
              <el-option
                v-for="item in levelOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </template>
          <template>
            <el-select v-model="status" placeholder="请选择状态" @change="getList">
              <el-option
                v-for="item in allStatusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </template>
        </div>
      </div>
      <div class="activities-content clear">
        <!-- 全部赛事 -->
        <template v-if="select_type=='-1'">
          <div class="event-item" v-for="(item,index) of listData" :key="index">
            <div class="event-poster">
              <router-link :to="{path: '/events/eventsDetails', query: {id: item.id}}">
                <img v-if="item.picture==''" src="../../../assets/images/events/bg-img.png" />
                <img v-else :src="BASE_URL+item.picture" :onerror="errorImg" alt="封面" />
              </router-link>
            </div>
            <div class="event-info">
              <p class="event-title">
                <router-link
                  :to="{path: '/events/eventsDetails', query: {id: item.id}}"
                >{{item.name}}</router-link>
              </p>
              <p class="start-time">{{item.start_time}}</p>
              <p class="place-info">
                <i class="place-icon"></i>
                <i :title="item.place">{{item.place}}</i>
              </p>
            </div>
            <span :class="'event-status progress'+item.show_status_int">{{item.show_status_text}}</span>
          </div>
        </template>
        <!-- 我参与的 -->
        <template v-if="select_type=='1'">
          <div class="event-item" v-for="(item,index) of listData" :key="index">
            <div class="event-poster">
              <router-link :to="{path: '/events/eventsDetails', query: {id: item.id}}">
                <img v-if="item.picture==''" src="../../../assets/images/events/bg-img.png" />
                <img v-else :src="BASE_URL+item.picture" :onerror="errorImg" alt="封面" />
              </router-link>
            </div>
            <div class="event-info">
              <p class="event-title">
                <router-link
                  :to="{path: '/events/eventsDetails', query: {id: item.id}}"
                >{{item.name}}</router-link>
              </p>
              <p class="review-status">
                <span :class="'rStatus'+item.checked_quota_status">
                  <i></i>
                  <i>{{item.checked_quota_status_text}}</i>
                </span>
              </p>
              <p class="start-time">{{item.start_time}}</p>
              <p class="place-info">
                <i class="place-icon"></i>
                 <i :title="item.place">{{item.place}}</i>
              </p>
            </div>
            <div class="delbox">
              <i class="el-icon-arrow-down"></i>
              <el-button class="del-btn" @click="delEvent(item)">删除</el-button>
            </div>
            <span :class="'event-status progress'+item.show_status_int">{{item.show_status_text}}</span>
          </div>
        </template>

        <template v-if="listData.length==0">
          <div v-if="select_type=='-1'||select_type=='2'" class="no-data-tips tips2"></div>
          <div v-if="select_type=='1'" class="no-data-tips tips5"></div>
        </template>
      </div>
      <div class="pageBox">
        <el-pagination
          v-if="total_number > page_size"
          @current-change="change_page"
          :page-size="page_size"
          :current-page="page_index"
          layout="prev, pager, next"
          :total="total_number"
        ></el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userId: this.$g.user_id,
      select_type: "-1", //赛事状态
      selectOption: [
        {
          value: "-1",
          label: "全部赛事"
        },
        {
          value: "1",
          label: "我参与的"
        }
      ],
      order: "time", //分类
      orderOption: [
        {
          value: "time",
          label: "时间"
        },
        {
          value: "count",
          label: "人数"
        },
        {
          value: "comment",
          label: "讨论"
        }
      ],
      errorImg:
        'this.src="' +
        require("../../../assets/images/events/bg-img.png") +
        '"',
      listData: [], //赛事数据
      //全部赛事select
      levelOptions: [
        {
          value: "-1",
          label: "全部赛事"
        },
        {
          value: "1",
          label: "校级赛事"
        },
        {
          value: "2",
          label: "年级赛事"
        },
        {
          value: "3",
          label: "班级赛事"
        }
      ],
      level_type: "-1",
      //全部状态select
      allStatusOptions: [
        {
          value: "-1",
          label: "全部状态"
        },
        {
          value: "1",
          label: "未开始"
        },
        {
          value: "2",
          label: "报名中"
        },
        {
          value: "3",
          label: "进行中"
        },
        {
          value: "4",
          label: "已结束"
        }
      ],
      status: "-1",
      order_type: "DESC", //DESC：倒序；ASC：升序
      // 分页：
      page_index: 1,
      page_size: 3,
      total_number: 0
    };
  },
  created() {
    this.getList();
  },
  watch: {},
  mounted() {},
  computed: {},
  methods: {
    // 获取赛事数据
    getList() {
      let success = data => {
        this.listData = data.data.data;
        this.total_number = data.data.data_sum;
      };
      this.$ajax({
        url: "api/competition/match",
        method: "get",
        params: {
          page_index: this.page_index,
          page_size: this.page_size,
          level_type: this.level_type,
          status: this.status,
          order: this.order,
          order_type: this.order_type,
          select_type: this.select_type,
          user_id: this.userId
        },
        func: {
          success: success
        }
      });
    },
    // 分页：
    change_page(val) {
      this.page_index = val;
      this.getList();
    },
    // 删除赛事：
    delEvent(item) {
      this.$confirm("删除后不可恢复，确定要删除吗？", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        customClass: "removeing"
      })
        .then(() => {
          let success = res => {
            this.$message.success(res.msg);
            this.getList();
          };
          this.$ajax({
            url: "api/competition/match",
            method: "delete",
            params: {
              id: item.id,
              type: 2, //	1：只删除参与赛事的相关记录(我参与的)；2：删除整个赛事(我发起的)；
              user_id: this.userId
            },
            func: { success: success }
          });
        })
        .catch(() => {});
    }
  }
};
</script>
<style lang="scss">
.search-bar {
  .el-radio-group {
    height: 60px;
    line-height: 70px;
    .el-radio__input {
      display: none;
    }
    .el-radio__label {
      font-size: 14px;
    }
  }
  .el-icon-sort-down {
    transform: rotateY(180deg);
  }
  .initiate-btn {
    width: 96px;
    height: 40px;
    padding: 0;
    margin-top: 10px;
  }
  .select-tools {
    .el-select {
      width: 200px;
      margin-left: 20px;
      .el-input__inner {
        height: 32px;
        line-height: 32px;
      }
      .el-input__icon {
        line-height: 32px;
      }
    }
  }
}
.activities-container {
  .el-radio-group {
    height: 32px;
    line-height: 32px;
  }
  .activities-content {
    margin-top: 20px;
  }
}
.event-title {
  max-width: 400px;
  a {
    display: inline-block;
    width: 100%;
    line-height: 20px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
}

.tips2 {
  background: url("../../../assets/images/events/pleaceholder (2).png")
    no-repeat center #fff;
}
.tips5 {
  background: url("../../../assets/images/events/pleaceholder (5).png")
    no-repeat center #fff;
}
.delbox {
  display: inline-block;
  width: 100px;
  height: 100px;
  position: absolute;
  top: 20px;
  right: 20px;
  text-align: end;
  &:hover {
    .del-btn {
      display: inline-block;
    }
    .el-icon-arrow-down {
      transform: rotate(180deg);
      -webkit-transform: rotate(180deg);
      -moz-transform: rotate(180deg);
      -o-transform: rotate(180deg);
      -ms-transform: rotate(180deg);
    }
  }
  .el-icon-arrow-down {
    transition: all 0.2s ease-in-out;
    -webkit-transition: all 0.2s ease-in-out;
    -moz-transition: all 0.2s ease-in-out;
    -o-transition: all 0.2s ease-in-out;
    font-size: 20px;
    cursor: pointer;
  }
  .del-btn {
    position: absolute;
    top: 30px;
    right: 0;
    display: none;
  }
}

.review-status {
  padding: 15px 0 0;
}
.place-info{
    max-width: 400px;
    white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
</style>

